package com.yami.shop.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.bean.model.UserSecurityConfig;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.service.UserSecurityConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import static com.yami.shop.common.response.ServerResponseEntity.success;

@RestController
@RequestMapping("/userSecurityConfig")
@Tag(description = "个人安全隐私设置", name = "个人信息")
public class UserSecurityConfigController {

    @Autowired
    private UserSecurityConfigService userSecurityConfigService;

    @PutMapping
    @Operation(summary =  "修改")
    public ServerResponseEntity updateByUserId(@RequestBody @Valid UserSecurityConfig userSecurityConfig) {
        userSecurityConfigService.updateByUserId(userSecurityConfig);
        return success();
    }

    @GetMapping("/getInfoByUserId")
    @Operation(summary =  "查询")
    public ServerResponseEntity getInfoByUserId(@RequestParam String userId) {
        UserSecurityConfig userSecurityConfig = userSecurityConfigService.getOne(new LambdaQueryWrapper<UserSecurityConfig>().eq(UserSecurityConfig::getUserId, userId));
        return success(userSecurityConfig);
    }
}
